<?php
/**
 * Notes:
 * User: wudg <544038230@qq.com>
 * Date: 2025/9/13 12:31
 */

namespace App\Dao\Users;


use App\Constants\System\SysStatusConst;
use App\Dao\BaseDao;
use App\Model\Users\UsersCardsInfo;

class UsersCardsInfoDao extends BaseDao
{


    public function getCardInfoBy(int $uid,int $toUid,int $cardId)
    {
        return UsersCardsInfo::query()
            ->where('uid','=',$uid)
            ->where('to_uid','=',$toUid)
            ->where('card_id','=',$cardId)
            ->where('status','=',SysStatusConst::NORMAL->value)
            ->first();
    }

    public function getCardInfoById(int $uid,int $cardId)
    {
        return UsersCardsInfo::query()
            ->where('id','=',$cardId)
            ->where('uid','=',$uid)
            ->where('status','=',SysStatusConst::NORMAL->value)
            ->first();
    }

    public function getCardInfoByToUidAndId(int $toUid,int $cardId)
    {
        return UsersCardsInfo::query()
            ->where('id','=',$cardId)
            ->where('to_uid','=',$toUid)
            ->where('status','=',SysStatusConst::NORMAL->value)
            ->first();
    }


    public function getCardInfoByCardNo(string $cardNo)
    {
        return UsersCardsInfo::query()
            ->where('card_no','=',$cardNo)
            ->where('status','=',SysStatusConst::NORMAL->value)
            ->first();
    }


    /**
     * 获取会员卡会员数量
     * @param int $toUid
     * @return int
     */
    public function getUserCardMembersNums(int $toUid)
    {
        return UsersCardsInfo::query()
            ->where('to_uid','=',$toUid)
            ->where('status','=',SysStatusConst::NORMAL->value)
            ->count();
    }
}